package cn.lger.icollege.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

/**
 * Code that Changed the World
 * Pro said
 * Created by Pro on 2018-05-17.
 */
@Controller
public class FileController {


    @GetMapping("/download/{fileName}")
    public void test03(@PathVariable String fileName, HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
        response.reset();
        response.setHeader("Content-Disposition", "attachment;filename="+URLEncoder.encode(fileName, "UTF-8"));
        response.setHeader("Connection", "close");
        response.setHeader("Content-Type", "application/octet-stream");
        request.getRequestDispatcher("/file/"+fileName).forward(request, response);

    }

}
